package com.level.restful.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * 获取未来七天日期以及星期几
 * @author tqf
 *
 */
public class WeekDateUtil {
	
	/**
	 * 获取未来6天的日期以及星期几
	 * @param dateForMat 日期格如：yyyy-MM-dd
	 * @return  
	 */
	public static Map<String,String[]> getSevDays(String dateForMat){
		Map<String, String[]> map = new HashMap<String, String[]>();
		//日期数组
		String days[] = new String[7];
		// 星期几数组
		String weeks[] = new String[7];
		String result[] = new String[2];
		for(int i=0;i<7;i++){
			result = getFetureDate(i,"yyyy-MM-dd");
			days[i] = result[0];
			switch(result[1]){
				case "1": weeks[i] = "日"; break;
				case "2": weeks[i] = "一"; break;
				case "3": weeks[i] = "二"; break;
				case "4": weeks[i] = "三"; break;
				case "5": weeks[i] = "四"; break;
				case "6": weeks[i] = "五"; break;
				case "7": weeks[i] = "六"; break;
			}
		}
		map.put("days", days);
		map.put("weeks", weeks);
		return map;
	}
	
	
	/**
     * 获取未来 第 past 天的日期
     * @param past
     * @return
     */
    public static String[] getFetureDate(int past,String fommat) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat(fommat);
        String result[] = new String[2];
        result[0] =	format.format(today);
        result[1] =	calendar.get(Calendar.DAY_OF_WEEK)+"";
//        System.out.println("day="+result[0]+"====week="+result[1]);
        return result;
    }

	/**
	 * 根据前台传值获取最多日期区间
	 * @param date
	 * @return
	 */
	public static String[] getDate(String date){
		String result[] = new String[2];
		switch (date){
			case "oneYear":
				result[0] = getFetureDate(-365,"yyyy-MM-dd")[0];
				result[1] = getFetureDate(0,"yyyy-MM-dd")[0];
				break;
			case "sixMonth" :
				result[0] = getFetureDate(-180,"yyyy-MM-dd")[0];
				result[1] = getFetureDate(0,"yyyy-MM-dd")[0];
				break;
			case "oneMonth" :
				result[0] = getFetureDate(-30,"yyyy-MM-dd")[0];
				result[1] = getFetureDate(0,"yyyy-MM-dd")[0];
				break;
			case "all" :
				result[0] = getFetureDate(-3650,"yyyy-MM-dd")[0];
				result[1] = getFetureDate(0,"yyyy-MM-dd")[0];
				break;
			default:
				result[0] = getFetureDate(-365,"yyyy-MM-dd")[0];
				result[1] = getFetureDate(0,"yyyy-MM-dd")[0];
				break;
		}
		return result;
	}
    
    public static void main(String [] str){
    	String[] map =   getFetureDate(1,"yyyy-MM-dd");
    	for(int i=0;i<map.length;i++){
    		System.out.println(map[i]);
    	}
    	
    }
}
